<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <title>我的问题</title>
    <%@include file="/WEB-INF/views/include/weixinhead.jsp" %>
    <script src="${ctxStatic}/modules/wechat/js/interface.js"></script>
</head>
<body>
<!--我的问题-->
<div data-role="page" id="detailes-page" class="page" >
    <div data-role="header" class="header header-1">我的问题
        <span class="return-btn"><a href="/f/campusinfo/person" data-ajax="false" data-transition="slideup"><img src="${ctxStatic}/modules/wechat/css/images/yuanjiaojuxing25.png" alt=""></a></span>
        <span ><a href="#editMyQuestion" data-ajax="false" data-transition="slideup"><span id="I-want-to-reply">我要提问</span></a></span>
    </div>
    <div role="main" class="content-2">
        <%--<a href="#" data-ajax="false">--%>
            <%--<div class="question-list">--%>
                <%--<div class="delQuestion">×</div>--%>
                <%--<div class="questionDetail">--%>
                    <%--<div class="question-title">111111111111111111111111111111111111111111111111111111111111111111111111</div>--%>
                    <%--<div class="question-content">1111111111111111111111111111111111111111111111111111111111</div>--%>
                <%--</div>--%>
            <%--</div>--%>
        <%--</a>--%>
    </div>
</div>
<div id="editMyQuestion" data-role="page">
    <div data-role="header" class="header header-1">我要提问
        <span class="return-btn"><a href="#detailes-page" data-transition="slideup"><img src="${ctxStatic}/modules/wechat/css/images/yuanjiaojuxing25.png" alt=""></a></span>
    </div>
    <div role="main" class="content-2" style="padding:12px;padding-top: 20px;">
            <div class="editMyQuestionTitle">标题
                <input type="text" placeholder="请输入标题" class="non-empty">
            </div>
            <div class="myQuestionContent">内容
                <textarea placeholder="请输入内容" class="non-empty"></textarea>
            </div>
            <div id="submitReplyBtn">提交</div>
    </div>
</div>
<div id="del">
    <div class="delContent">确认删除当前问题？</div>
    <div class="delContent exit">确定</div>
    <div class="delContent exit">取消</div>
</div>
<div id="grayLayer"></div>
<script>
    $(document).delegate(".delQuestion","tap",function(){
        var index=$(".delQuestion").index(this);
        $("#del").fadeIn(500);
        $("#grayLayer").height($(document).height());
        questionId=$(".questionDetail").eq(index).attr("id");
    })
    /*取消删除*/
    $(".exit").on("tap",function(){
        var index=$(".exit").index(this);
        if(index==0){       //确定
            $("#del").fadeOut(500);
            $("#grayLayer").height("0px");
            $.ajax({
                url:interfaceDelQuestion+generateMixed(9),
                type:'post',
                data:{id:questionId},
                success:function(data){
                    if(data.success){
                        alert(data.message);
                        window.location.href="/f/campusinfo/myQuestions"+generateMixed(9);
                    }else{
                        alert(data.message);
                    }
                }
            })
        }else if(index==1){     //取消
            $("#del").fadeOut(500);
            $("#grayLayer").height("0px");
        }
    })
</script>
<script>
    // $("#submitReplyBtn").click(function () {
    //     $.mobile.changePage("#detailes-page");
    // });
    $(document).ready(function () {
        /*先判断用户是否在线*/
        $.ajax({
            url: interfaceGetState,
            type: 'post',
            success: function (data) {
                if (data.status == 0) {    //已登录
                    $.ajax({
                        url:interfaceMyQuestion+generateMixed(9),
                        type:'post',
                        success:function (data) {
                            // console.log(data);
                            for(var i=0;i<data.page.length;i++){
                                $(".content-2").eq(0).append("<div class='question-list'>" +
                                    "                <div class='delQuestion'>×</div>"+
                                    "                <div class='questionDetail' id='"+data.page[i].id+"'>"+
                                    "                  <div class='question-title'>"+data.page[i].title+"</div>\n" +
                                    "                  <div class='question-content'>"+data.page[i].content+"</div>\n" +
                                    "                 </div>"+
                                    "            </div>");
                            }
                        }
                    })
                } else {    //未登录
                    alert("请先登录");
                    if(window.sessionStorage){
                        var url=window.location.href;
                        sessionStorage.setItem("prePage",url);
                    }
                    window.location.href="/f/campusinfo/login"+generateMixed(9);
                    return false;
                }
            }
        })
        /*我要提问-提交*/
        $("#submitReplyBtn").off("tap").on("tap",function(){
            /*先判断用户是否在线*/
            $.ajax({
                url: interfaceGetState,
                type: 'post',
                success: function (data) {
                    if (data.status == 0) {    //已登录
                        var length=$(".non-empty").length;
                        var title=$(".non-empty").eq(0).val();
                        var content=$(".non-empty").eq(1).val();
                        if(title!=''&&content!=''){
                            $.ajax({
                                url:interfaceEditProblem+generateMixed(9),
                                type:'post',
                                data:{title:title,content:content},
                                success:function(data){
                                    // console.log(data);
                                    if(data.success){
                                        alert(data.message);
                                        window.location.href="/f/campusinfo/myQuestions"+generateMixed(9);
                                    }else{
                                        alert(data.message);
                                    }
                                }
                            })
                        }
                    } else {    //未登录
                        alert("请先登录");
                        if(window.sessionStorage){
                            var url=window.location.href;
                            sessionStorage.setItem("prePage",url);
                        }
                        window.location.href="/f/campusinfo/login"+generateMixed(9);
                        return false;
                    }
                }
            })
        });
        $(document).delegate(".questionDetail","tap",function(){
            // var index=$(".questionDetail").index(this);
            // questionId=$(".questionDetail").eq(index).attr("id");
            questionId=$(this).attr("id");
            // console.log(questionId);
            window.location="/f/campusinfo/problemConsulting?id="+questionId+generateMixed(9);
        })
    })

</script>
</body>
</html>
